<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>学生成绩</title>
    <script type="text/javascript" th:src="@{/static/layui/layui.js}"></script>
    <link rel="stylesheet" type="text/css" th:href="@{/static/layui/css/layui.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/static/css/addnews.css}"/>
</head>
<body>
<form class="layui-form layui-form-pane" style="padding: 10px;">

    <div class="layui-row">
        <div class="layui-col-xs12 layui-col-sm12 layui-col-md3">
            <fieldset class="layui-elem-field">
                <legend>精确查询</legend>
                <div class="layui-field-box">
                    <div class="layui-col-xs12">
                        <div class="layui-form-item">
                            <label class="layui-form-label">班级名称</label>
                            <div class="layui-input-block">
                                <select id="selByClassName" name="selByClassName" lay-filter="selByClassName"
                                        lay-verify="selByClassName" lay-search></select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-xs12">
                        <div class="layui-form-item">
                            <label class="layui-form-label">学期</label>
                            <div class="layui-input-block">
                                <select name="stime" id="stime" lay-filter="stime"
                                        lay-verify="stime" lay-search>
                                    <option value="" disabled selected hidden>请选择</option>
                                    <option value="1">大一上学期</option>
                                    <option value="2">大一下学期</option>
                                    <option value="3">大二上学期</option>
                                    <option value="4">大二下学期</option>
                                    <option value="5">大三上学期</option>
                                    <option value="6">大三下学期</option>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
            </fieldset>
        </div>
        <div class="layui-col-xs12 layui-col-sm12 layui-col-md9">
            <fieldset class="layui-elem-field">
                <legend>分级/分类查询</legend>
                <div class="layui-field-box">
                    <div class="layui-col-xs12 layui-col-sm12 layui-col-md4">
                        <div class="layui-form-item">
                            <label class="layui-form-label">系部名称</label>
                            <div class="layui-input-block">
                                <select id="selByDpm" name="selByDpm" lay-filter="selByDpm" lay-verify="selByDpm"
                                        lay-search></select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-xs12 layui-col-sm12 layui-col-md4">
                        <div class="layui-form-item">
                            <label class="layui-form-label">专业名称</label>
                            <div class="layui-input-block">
                                <select id="selByMajor" name="selByMajor" lay-filter="selByMajor"
                                        lay-verify="selByMajor" lay-search></select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-xs12 layui-col-sm12 layui-col-md4">
                        <div class="layui-form-item">
                            <label class="layui-form-label">年级名称</label>
                            <div class="layui-input-block">
                                <select id="selByGrade" name="selByGrade" lay-filter="selByGrade"
                                        lay-verify="selByGrade" lay-search></select>
                            </div>
                        </div>
                    </div>
                </div>
            </fieldset>
        </div>
    </div>
</form>
<table id="evlist" lay-filter="gradeTable"></table>
<script>
    layui.use(['jquery', 'layer', 'form', 'table', 'laydate'], function () {
        var $ = layui.$ //重点处
            , layer = layui.layer
            , form = layui.form
            , table = layui.table
            , layer = layui.layer
            , laydate = layui.laydate;
        var tableId;

        //获取分页数据列表
        tableId = table.render({
            elem: '#evlist'
            ,
            url: '/selAllExam'
            ,
            cols: [
                [
                    {field: 'sname', title: '学生'}
                    , {field: 'cname', title: '课程'}
                    , {field: 'ccredit', title: '学分'}
                    , {field: 'type', title: '类别'}
                    , {field: 'normalexam', title: '平时成绩'}
                    , {field: 'testexam', title: '考试成绩'}
                    , {field: 'sumexam', title: '综合成绩'}
                    , {
                    field: 'stime', title: '学期', templet: function (data) {
                        if (data.stime == '1') {
                            return '大一上学期'
                        } else if (data.stime == '2') {
                            return '大一下学期'
                        } else if (data.stime == '3') {
                            return '大二上学期'
                        } else if (data.stime == '4') {
                            return '大二下学期'
                        } else if (data.stime == '5') {
                            return '大三上学期'
                        } else if (data.stime == '6') {
                            return '大三下学期'
                        }
                    }
                }
                ]
            ]
            ,
            page: true
            ,
            even: true
            ,
            id: 'tableReload'
        });
        /***************************************************************条件查询*********************************************************************/

        /**
         * 默认填充
         */
        //填充班级
        $.ajax({
            type: 'post',
            url: '/schoolmanage/tjselclass?page=1&limit=1000',
            data: {},
            success: function (alldata) {

                var result = alldata.data;
                var lists = "<option value='all'>全部</option>";
                for (var i in result) {
                    lists += "<option value='" + result[i].classname + "'>" + result[i].classname + "</option>";
                }
                $('#selByClassName').html(lists);
                form.render();
            }
        });
        //填充系部
        $.ajax({
            type: 'post',
            url: '/schoolmanage/tjseldpm?page=1&limit=1000',
            data: {},
            success: function (alldata) {

                var result = alldata.data;
                var lists = "<option value='all'>请选择</option>";
                for (var i in result) {
                    lists += "<option value='" + result[i].dname + "'>" + result[i].dname + "</option>";
                }
                $('#selByDpm').html(lists);
                form.render();
            }
        });
        //按班级名查询
        form.on('select(selByClassName)', function (seldata) {
            if (seldata.value == 'all') {
                tableId.reload({
                    url: '/selAllExam'
                });
            } else {
                tableId.reload({
                    url: '/selAllExam?classname=' + seldata.value
                });
            }
            form.render();
        });
        //按系名查询
        form.on('select(selByDpm)', function (seldata) {
            if (seldata.value == 'all') {

            } else {
                tableId.reload({
                    url: '/selAllExam?dname=' + seldata.value
                });
            }
            //填充专业
            $.ajax({
                type: 'post',
                url: '/schoolmanage/tjselmajor?page=1&limit=1000',
                data: {
                    dname: $("#selByDpm option:selected").val()
                },
                success: function (alldata) {

                    var result = alldata.data;
                    var lists = "<option value='all'>请选择</option>";
                    for (var i in result) {
                        lists += "<option value='" + result[i].mname + "'>" + result[i].mname + "</option>";
                    }
                    $('#selByMajor').html(lists);
                    form.render();
                }
            });
            $('#selByGrade').html("");
            form.render();
        });
        //按专业名查询
        form.on('select(selByMajor)', function (seldata) {
            if (seldata.value == 'all') {

            } else {
                tableId.reload({
                    url: '/selAllExam?mname=' + seldata.value
                });
            }
            //填充年级
            $.ajax({
                type: 'post',
                url: '/schoolmanage/tjselgrade?page=1&limit=1000',
                data: {
                    mname: $("#selByMajor option:selected").val()
                },
                success: function (alldata) {

                    var result = alldata.data;
                    var lists = "<option value='all'>请选择</option>";
                    for (var i in result) {
                        lists += "<option value='" + result[i].gname + "'>" + result[i].gname + "</option>";
                    }
                    $('#selByGrade').html(lists);
                    form.render();
                }
            });
        });
        //按年级名查询
        form.on('select(selByGrade)', function (seldata) {
            if (seldata.value == 'all') {
            } else {
                tableId.reload({
                    url: '/selAllExam?gname=' + seldata.value + '&mname=' + $("#selByMajor option:selected").val()
                });
            }
        });
        form.on('select(stime)', function (seldata) {
            //执行重载
            table.reload('tableReload', {
                page: {
                    curr: 1 //重新从第 1 页开始selTeacher
                }
                , where: {
                    stime: seldata.value
                }
            });
        });
    });
</script>
</body>
</html>